package org.jeecg.modules.demo.temple.dashboard.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.demo.temple.dashboard.controller.vo.DashBoardQuery;
import org.jeecg.modules.demo.temple.order.service.ITempleActivityOrderService;
import org.jeecg.modules.demo.temple.order.service.ITempleDonationOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "驾驶舱")
@RestController
@RequestMapping("/templeDashboard")
@Slf4j
public class DashboardController {
    // 捐赠Service
    @Autowired
    private ITempleDonationOrderService templeDonationOrderService;
    // 活动Service
    @Autowired
    private ITempleActivityOrderService templeActivityOrderService;

    /**
     * @return Result
     * @Description 查询活动类、捐赠统计数据
     * @date 2022/6/13 16:38
     */
    @ApiOperation(value = "查询捐赠订单统计数据", notes = "查询捐赠订单统计数据")
    @GetMapping({"/dataStatistical", "/api/dataStatistical"})
    public Result dataStatistical() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 判断用户类型
        if (loginUser != null) {
            // 捐赠类数据
            Map todayDonationData = templeDonationOrderService.todayDonationData(loginUser.getOrgCode());
            List<Map> classifyDonationData = templeDonationOrderService.classifyDonationData(loginUser.getOrgCode());
            // 活动类数据
            Map todayActivityData = templeActivityOrderService.todayActivityData(loginUser.getOrgCode());
            List<Map> classifyActivityData = templeActivityOrderService.classifyActivityData(loginUser.getOrgCode());

            Map<String, Object> todayOrHistoryData = new HashMap();
            todayOrHistoryData.put("todayDonationData", todayDonationData);
            todayOrHistoryData.put("classifyDonationData", classifyDonationData);
            todayOrHistoryData.put("todayActivityData", todayActivityData);
            todayOrHistoryData.put("classifyActivityData", classifyActivityData);
            return Result.OK(todayOrHistoryData);
        }

        return Result.OK();
    }

    /**
     * @return Result
     * @Description 查询7天的数据
     * @date 2022/6/15 9:47
     */

    @ApiOperation(value = "查询近7日统计数据", notes = "查询近7日统计数据")
    @GetMapping({"/query7DayData", "/api/query7DayData"})
    public Result query7DayData() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 判断用户类型
        if (loginUser != null) {
            List<Map> donation7DayData = templeDonationOrderService.donation7DayData(loginUser.getOrgCode());
            List<Map> activity7DayData = templeActivityOrderService.activity7DayData(loginUser.getOrgCode());
            Map<String, Object> queryData = new HashMap();
            queryData.put("donation7DayData",donation7DayData) ;
            queryData.put("activity7DayData",activity7DayData) ;
            return Result.OK(queryData) ;
        }

        return Result.OK();
    }

    /**
     * @return Result
     * @Description 查询近一个月数据
     * @date 2022/6/15 9:47
     */
    @ApiOperation(value = "查询近1个月统计数据", notes = "查询近1个月统计数据")
    @GetMapping({"/queryOneMonthData", "/api/queryOneMonthData"})
    public Result queryOneMonthData() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 判断用户类型
        if (loginUser != null) {
            List<Map> donationOneMonthData = templeDonationOrderService.donationOneMonthData(loginUser.getOrgCode());
            List<Map> activityOneMonthData = templeActivityOrderService.activityOneMonthData(loginUser.getOrgCode());
            Map<String, Object> queryData = new HashMap();
            queryData.put("donationOneMonthData",donationOneMonthData) ;
            queryData.put("activityOneMonthData",activityOneMonthData) ;
            return Result.OK(queryData) ;
        }
        return Result.OK();
    }

    /**
     * @return Result
     * @Description 查询近3个月数据
     * @date 2022/6/15 9:48
     */
    @ApiOperation(value = "查询近3个月统计数据", notes = "查询近3个月统计数据")
    @GetMapping({"/queryThreeMonthData", "/api/queryThreeMonthData"})
    public Result queryThreeMonthData() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 判断用户类型
        if (loginUser != null) {
            List<Map> donationThreeMonthData = templeDonationOrderService.donationThreeMonthData(loginUser.getOrgCode());
            List<Map> activityThreeMonthData = templeActivityOrderService.activityThreeMonthData(loginUser.getOrgCode());
            Map<String, Object> queryData = new HashMap();
            queryData.put("donationThreeMonthData",donationThreeMonthData) ;
            queryData.put("activityThreeMonthData",activityThreeMonthData) ;
            return Result.OK(queryData) ;
        }
        return Result.OK();
    }

    /**
     * @return Result
     * @Description 查询近6个月数据
     * @date 2022/6/15 9:48
     */
    @ApiOperation(value = "查询近6个月统计数据", notes = "查询近6个月统计数据")
    @GetMapping({"/queryHalfData", "/api/queryHalfData"})
    public Result queryHalfData() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 判断用户类型
        if (loginUser != null) {
            List<Map> donationHalfData = templeDonationOrderService.donationHalfData(loginUser.getOrgCode());
            List<Map> activityHalfData = templeActivityOrderService.activityHalfData(loginUser.getOrgCode());
            Map<String, Object> queryData = new HashMap();
            queryData.put("donationHalfData",donationHalfData) ;
            queryData.put("activityHalfData",activityHalfData) ;
            return Result.OK(queryData) ;

        }
        return Result.OK();
    }

    /**
     * @return Result
     * @Description 查询近1年数据
     * @date 2022/6/15 9:49
     */
    @ApiOperation(value = "查询近1年统计数据", notes = "查询近1年统计数据")
    @GetMapping({"/queryOneYearData", "/api/queryOneYearData"})
    public Result queryOneYearData() {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 判断用户类型
        if (loginUser != null) {

            List<Map> donationOneYearData = templeDonationOrderService.donationOneYearData(loginUser.getOrgCode());
            List<Map> activityOneYearData = templeActivityOrderService.activityOneYearData(loginUser.getOrgCode());

            Map<String, Object> queryData = new HashMap();
            queryData.put("donationOneYearData",donationOneYearData) ;
            queryData.put("activityOneYearData",activityOneYearData) ;
            return Result.OK(queryData) ;
        }
        return Result.OK();
    }

    /**
     *
     * @Description 根据时间区间查询
     * @date 2022/6/20 17:01
     * @param dashBoardQuery
     * @return Result
     */

    @ApiOperation(value = "根据时间区间查询数据", notes = "查询区间内的统计数据")
    @GetMapping({"/dashBoardDateQuery", "/api/dashBoardDateQuery"})
    public Result dashBoardDateQuery(DashBoardQuery dashBoardQuery){
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 判断用户类型
        if (loginUser != null) {
            List<Map> donationDateQuery = templeDonationOrderService.donationDashBoardQuery(loginUser.getOrgCode(), dashBoardQuery.getBegin(), dashBoardQuery.getEnd());
            List<Map> activityDateQuery = templeActivityOrderService.activityDashBoardQuery(loginUser.getOrgCode(), dashBoardQuery.getBegin(), dashBoardQuery.getEnd());
            Map<String, Object> queryData = new HashMap();
            queryData.put("donationDateQuery",donationDateQuery) ;
            queryData.put("activityDateQuery",activityDateQuery) ;
            return Result.OK(queryData) ;
        }

        return null ;

    }



}
